﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using Microsoft.Xna.Framework;

namespace ZoambieGaem {
    class MasterUpdate {

        private Logic logic;
        private ZoambieLogic zLogic;

        private Thread updateThread = null;
        public Boolean running;
        private long lastCount;
        private long updateInterval = 2;

        public MasterUpdate(Master m) {
            zLogic = new ZoambieLogic();
            logic = new Logic();

            running = true;
            updateThread = new Thread((Update));
            updateThread.Name = "Logic Thread";
            updateThread.Start(m);

        }

        public void Update(Object obj) {
            while (running) {
                Master m = (Master)obj;
                
                    logic.update(m);
                    zLogic.update(m);
                    if (m.frameDrawn)
                        m.frameDrawn = false;
                
                Thread.Sleep(5);
            }
            if (!running) {
                Dispose(true);
            }
        }

        protected void Dispose(bool disposing) {
            try {
                if (disposing) 
                    if (updateThread != null) 
                        updateThread.Abort();
            }
            finally {
                zLogic = null;
                logic = null;
                updateThread = null;
            }
        }

    }
}
